<template>
    <view class="square_components_friends">
        <z-paging ref="Zpaging" class="lis_div" v-model="list" @query="getList" :refresher-enabled="true" :fixed="false" :refresher-theme-style="'white'">
            <div class="lis_box">
                <div class="li" v-for="(li,key) in list" :key="key">
                    <div class="li_user">
                        <pub-image class="headimg" :src="li.avatar" :mode="'aspectFill'"
                            @imgClick="$comFun.openWin('/pages/mine/friend_center',{userId:li.onlyId})"></pub-image>
                        <div class="text">
                            <div class="name">{{ li.nickName }}
                                <div class="span_2" v-if="li.vipAccount"></div>
                                <div class="span_3">LV.{{ li.grade }}</div>
                            </div>
                            <div class="time">{{ li.createTime }}</div>
                        </div>
                    </div>
                    <div class="li_content" v-if="li.content">{{ li.content }}</div>
                    <div class="li_imgs">
                        <div class="img" @click="$comFun.toPreviewImage(img,li.pic)" v-for="(img,imgKey) in li.pic"
                            :key="imgKey" :style="{backgroundImage:'url('+img+')'}">
                        </div>
                    </div>
                    <div class="li_info">
                        <div class="time"></div>
                        <div class="more">
                            <div class="txt" @click="toThumb(li,key)">
                                <text v-if="li.selfThumb==1" class="icon-font-basic icon-b-taoxin3"></text>
                                <text v-if="li.selfThumb==0" class="icon-font-basic icon-b-taoxin"></text>{{ li.thumb }}
                            </div>
                            <div class="txt" @click="openFriendsComments(li,key)">
                                <text class="icon-font-basic icon-b-31pinglun"></text>{{ li.commentNum }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </z-paging>

        <div class="post_btn" v-if="openType==1" @click="$comFun.openWin('/pages/square/friends_post')">
            <div class="icon">
                <text class="icon-font-basic icon-b-as-5"></text>
            </div>
            <!-- <div class="txt">发布</div> -->
        </div>
    </view>
</template>

<script>
export default {
    props: {
        openType: {
            type: Number,
            default: 0
        }
    },
    data() {
        return {
            list: [],
            isLoad: false,
        };
    },
    onLoad() { },
    methods: {
        getZpagingList(type) {
            switch (type) {
                case 'init':
                    if (!this.isLoad) {
                        this.isLoad = true;
                        this.$comFun.openLoading();
                        this.$refs.Zpaging.reload();
                    }
                    break;
                case 'reload':
                    this.$refs.Zpaging.reload();
                    break;
                default:
                    break;
            }
        },
        async getList(pageNo, pageSize) {
            let data = {
                pageNo: pageNo,
                pageSize: pageSize,
            };
            const res = await this.$request.get(this.openType == 1 ? 'quan/quanPage' : 'quan/quanSquarePage', data);
            this.$comFun.closeLoading();
            // console.log(res);
            if (res.code == 200) {
                res.result.records.forEach(li => {
                    li.pic = li.pic ? li.pic.split(",") : [];
                })
                this.$refs.Zpaging.complete(res.result.records);
            } else {
                this.$refs.Zpaging.complete(false);
            }
        },
        async toThumb(info, key) {
            if (info.selfThumb) {
                this.$comFun.toast('已点赞');
                return;
            }
            this.$comFun.openLoading();
            const res = await this.$request.get('quan/contentThumb', {
                contentId: info.id
            });
            // console.log(res);
            this.$comFun.closeLoading();
            if (res.code == 200) {
                this.$comFun.toast('点赞成功');
                this.list[key].selfThumb = 1;
                this.list[key].thumb++;
            } else {
                this.$comFun.toast(res.message);
            }
        },
        openFriendsComments(info, key) {
            this.$emit('openFriendsComments', {
                id: info.id,
                key: key
            })
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/square.scss";
</style>
